<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<title>用户修改</title>

<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jq.js"></script>
<script src="js/admin.js"></script>
</head>
<script type="text/javascript">
$(function(){
	$.post("MenuServlet",{method:"findAllMenu"},function(data){
		//将Json转为js对象
		eval("var menu = "+data);
		//获取下拉框对象
		var sel = $("#menupId");
		//请空下拉框
		sel.empty();
		//若无主菜单，则自为主菜单
		sel.append("<option value ='0'>无主菜单</option>");
		//初始化时候只遍历主菜单
		for(var i = 0;i<menu.length;i++){
			if(menu[i].menupId==0){
				sel.append("<option value ='"+menu[i].menuId+"'>"+menu[i].menuName+"</option>")
			}
		}
		//定义触发父节点的指定change事件
		$("#menupId").trigger("change");
	});
	//当所属主菜单被触发的时候，查询出来该主菜单下的所属的次级菜单
	$("#menupId").change(function(){
		var menupId =$("#menupId").val();
		if(menupId == 0){
			$("#secondmenu").css("display","none");
		}else{
			$("#secondmenu").css("display","");
			$.post("MenuServlet",{menupId:menupId,method:"findSecondMenu"},function(data){
				//将Json转为js对象
				eval("var menu = "+data);
				//获取下拉框对象
				var sel = $("#secondpId");
				//请空下拉框
				sel.empty();
				//若无主菜单，则自为主菜单
				sel.append("<option value ='0'>无所属次级菜单</option>");
				//遍历
				for(var i = 0;i<menu.length;i++){
					sel.append("<option value ='"+menu[i].menuId+"'>"+menu[i].menuName+"</option>")
				}
			})
		}
		
	})
	
})
</script>
<body>
<div class="panel admin-panel ">
  <div class="panel-head" ><strong class="icon-reorder">修改分类</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="MenuServlet?method=addMenu"> 
    <!-- 主菜单 -->       
      <div class="form-group">
        <div class="label">
          <label>所属主菜单：</label>
        </div>
        <div class="field">
        <select name="menupId" id="menupId" class="input w50" >
        </select>
          <div class="tips"></div>
        </div>
      </div>        
      
      <div id="secondmenu" style="display: none">
      <!-- 次级菜单 -->       
      <div class="form-group">
        <div class="label">
          <label>所属次级菜单：</label>
        </div>
        <div class="field">
        <select name="secondpId" id="secondpId" class="input w50" >
        	<option value="0">无所属次级菜单</option>
        </select>
          <div class="tips"></div>
        </div>
      </div> 
      </div>
      
      <!-- 次级菜单 -->       
      <div class="form-group">
        <div class="label">
          <label>菜单编号：</label>
        </div>
        <div class="field">
        <input type="text" name="menuId" id="menuId" class="input w50" data-validate="required:请输入菜单编号">
          <div class="tips"></div>
        </div>
      </div> 
      
     <!-- 菜单名称 -->             
      <div class="form-group">
        <div class="label">
          <label>菜单名称：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="menuName" data-validate="required:请输入菜单名称"/>         
        </div>
      </div>
            
     <!-- url -->            
      <div class="form-group">
        <div class="label">
          <label>url：</label>
        </div>
        <div class="field">
        <input type="text" class="input w50" name="url" data-validate="required:请输入url"/>
        </div>
      </div>
      

      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
</body>

</html>